Ext.ns("crs.grid");

crs.grid.ApplyingFormReviewGridPanel = Ext.extend(Ext.grid.EditorGridPanel, {

	/* begin of fields initialization */
	autoHeight : true,
	review_url : 'review_reviewApplication.do',
	default_url : 'review_applicationsPendingReview.do',
	defaultProxy : '',
	pageSize : 15,
	closable : true,
	params : '',
	detailWindow : {},
	detailForm : {},
	root : 'listCopyrightApplication',
	totalProperty : 'pagination.totalCount',
	title : '待审核著作权登记或转让',
	viewConfig : {
		deferEmptyText : false,
		emptyText : '没有可显示数据',
		forceFit : true
	},
	params : {},
	defaultProxy : {},
	fields : ['id', 'softFullName', 'softForShort', 'name1', 'editionNumber',
			'developCircs', 'completeDate', 'publishStatus', 'appearDate',
			'appearAreaCountry', 'appearAreaCity', 'developMode', 'applyTime',
			'origRegisterNumber', 'origSoftModifyDescription',
			'programLanguage', 'softFunctionAndSpecialty', 'softNumber',
			'softwareEnv', 'hardwareEnv', 'sourceCodeCapacity', 'state',
			'idTypes1', 'idNumber1', 'peopleType1', 'province1', 'garden1',
			'country1', 'city1', 'busType1'],
	columns : [{
				header : 'id',
				hidden : true,
				dataIndex : 'id'
			}, {
				header : '著作权人',
				dataIndex : 'name1'
			}, {
				header : '软件名称',
				dataIndex : 'softFullName'
			}, {
				header : '版本号',
				dataIndex : 'editionNumber'
			}, {
				header : '申请时间',
				dataIndex : 'applyTime'
			}],
	sm : new Ext.grid.RowSelectionModel({
				singleSelect : true
			}),
	initComponent : function() {
		this.buildProxies();
		this.initDetailForm();
		this.params = this.buildParams();
		this.store = this.buildStore();
		// this.columns = this.buildColumns();
		this.tbar = this.buildTbar();
		this.bbar = this.buildBbar();
		crs.grid.ApplyingFormReviewGridPanel.superclass.initComponent
				.call(this);

		this.store.load(this.params);
	},
	initDetailForm : function() {
		this.detailForm = new Ext.form.FormPanel({
					frame : true,
					title : '详细信息',
					labelAlign : 'right',
					labelStyle : 'font-weight:bold;',
					labelWidth : 100,
					width : 750,
					/*
					 * 'name1' 'editionNumber', 'completeDate', 'publishStatus',
					 * 'appearAreaCountry', 'appearAreaCity', 'developMode',
					 * 'applyTime', 'origRegisterNumber',
					 * 'origSoftModifyDescription', 'programLanguage',
					 * 'softFunctionAndSpecialty', 'softNumber', 'softwareEnv',
					 * 'hardwareEnv', 'sourceCodeCapacity', 'state', 'idTypes1',
					 * 'idNumber1', 'peopleType1', 'province1', 'garden1',
					 * 'country1','city1','busType1'
					 */
					items : [{
								layout : 'column',
								items : [{ // column #1
									columnWidth : .33,
									layout : 'form',
									items : [{
												xtype : 'textfield',
												fieldLabel : '软件全称',
												name : 'softFullName',
												disabled : true,
												anchor : '90%'

											}, {
												xtype : 'radiogroup',
												fieldLabel : '软件作品说明',
												disabled : true,
												name : 'developCircs', // 后台返回的JSON格式，直接赋值；
												anchor : '90%',
												items : [{
															boxLabel : '原创',
															name : 'developCircs',
															inputValue : 1
														}, {
															boxLabel : '修改',
															name : 'developCircs',
															inputValue : 2
														}]
											}, {
												xtype : 'textfield',
												fieldLabel : '首发日期',
												disabled : true,
												name : 'appearDate',
												anchor : '90%'

											}, {
												xtype : 'textfield',
												fieldLabel : '著作权人',
												disabled : true,
												name : 'name1',
												anchor : '90%'

											}, {
												xtype : 'combo',
												fieldLabel : '证件类型',
												valueField : 'value',
												displayField : 'text',
												name : 'idTypes1',
												hiddenName : 'idTypes1',
												disabled : true,
												anchor : '90%',
												mode : 'local',
												store : idTypeStore
											}, {
												xtype : 'textfield',
												fieldLabel : '国家',
												disabled : true,
												name : 'country1',
												anchor : '90%'

											}]
										// close items for first column
								}, {
									columnWidth : .33,
									layout : 'form',
									items : [{
												xtype : 'textfield',
												fieldLabel : '软件简称',
												name : 'softForShort',
												disabled : true,
												anchor : '90%'

											}, {
												xtype : 'textfield',
												fieldLabel : '开发完成日期',
												disabled : true,
												name : 'completeDate',
												anchor : '90%'

											}, {
												xtype : 'textfield',
												fieldLabel : '首次发表国家',
												disabled : true,
												name : 'appearAreaCountry',
												anchor : '90%'

											}, {
												xtype : 'combo',
												fieldLabel : '类别',
												valueField : 'value',
												displayField : 'text',
												name : 'peopleType1',
												hiddenName : 'peopleType1',
												disabled : true,
												anchor : '90%',
												mode : 'local',
												store : peopleTypeStore
											}, {
												xtype : 'textfield',
												fieldLabel : '证件号码',
												disabled : true,
												name : 'idNumber1',
												anchor : '90%'

											}, {
												xtype : 'textfield',
												fieldLabel : '省份',
												disabled : true,
												name : 'province1',
												anchor : '90%'

											}]
										// close items for second column
									}, {
									columnWidth : .33,
									layout : 'form',
									items : [{
												xtype : 'textfield',
												fieldLabel : '版本号',
												name : 'editionNumber',
												disabled : true,
												anchor : '90%'

											}, {
												xtype : 'radiogroup',
												fieldLabel : '发表状态',
												disabled : true,
												name : 'publishStatus', // 后台返回的JSON格式，直接赋值；
												anchor : '90%',
												items : [{
															boxLabel : '已发表',
															name : 'publishStatus',
															inputValue : 1
														}, {
															boxLabel : '未发表',
															name : 'publishStatus',
															inputValue : 0
														}]
											}, {
												xtype : 'textfield',
												fieldLabel : '首次发表城市',
												disabled : true,
												name : 'appearAreaCity',
												anchor : '90%'

											}, {
												xtype : 'textfield',
												fieldLabel : '企业类别',
												disabled : true,
												name : 'busType1',
												anchor : '90%'

											}, {
												xtype : 'textfield',
												fieldLabel : '园区',
												disabled : true,
												name : 'garden1',
												anchor : '90%'

											}, {
												xtype : 'textfield',
												fieldLabel : '城市',
												disabled : true,
												name : 'city1',
												anchor : '90%'

											}]
										// close items for second column
								}]
							}, {
								layout : 'column',
								items : [{ // column #1
									columnWidth : .5,
									layout : 'form',
									items : [{
												xtype : 'textfield',
												fieldLabel : '编程语言',
												name : 'programLanguage',
												disabled : true,
												anchor : '95%'

											}, {
												xtype : 'textarea',
												fieldLabel : '硬件环境',
												name : 'hardwareEnv',
												disabled : true,
												anchor : '95%'

											}, {
												xtype : 'textarea',
												fieldLabel : '主要功能和技术特点 ',
												name : 'softFunctionAndSpecialty',
												disabled : true,
												anchor : '95%'
											}]
										// close items for first column
								}, {
									columnWidth : .5,
									layout : 'form',
									items : [{
												xtype : 'textfield',
												fieldLabel : '源程序量',
												name : 'sourceCodeCapacity',
												disabled : true,
												anchor : '95%'
											}, {
												xtype : 'textarea',
												fieldLabel : '软件环境',
												name : 'softwareEnv',
												disabled : true,
												anchor : '95%'
											}]
										// close items for second column
									}]

							}]
				});

		this.detailWindow = new Ext.Window({
					frame : true,
					plain : true,
					modal : true,
					resizable : false,
					title : '详细信息',
					buttonAlign : "right",
					closeAction : "hide",
					closable : true,
					bodyStyle : "padding:4px",
					width : 750,
					autoHeight : true,
					layout : "form",
					items : [this.detailForm],
					buttons : [{
								text : "审核通过",
								handler : this.doReview,
								scope : this
							}, {
								text : "审核不通过",
								handler : this.doRefuse,
								scope : this
							}, {
								text : "取消",
								handler : function() {
									this.detailWindow.hide();
								},
								scope : this
							}]
				});
	},

	buildTbar : function() {
		return new Ext.Toolbar({
					items : ['-', {
								text : '详细信息',
								handler : this.showDetail,
								scope : this
							}, '-']
				});
	},
	/* end of components appending to this panel */
	buildStore : function() {

		return new Ext.data.Store({
					proxy : this.defaultProxy,
					reader : new Ext.data.JsonReader({
								root : this.root,
								totalProperty : this.totalProperty,
								fields : this.fields
							})
				});

	},

	buildProxies : function() {

		this.defaultProxy = new Ext.data.HttpProxy({
					url : this.default_url,
					method : 'post'
				});
	},
	buildBbar : function() {
		return new Ext.PagingToolbar({
					store : this.store,
					pageSize : this.pageSize,
					displayInfo : true
				});
	},
	buildParams : function() {
		var dataPost = {};
		dataPost.params = {};
		dataPost.params.start = 0;
		dataPost.params.limit = this.pageSize;
		return dataPost;
	},

	/* begin of handler implementation */
	showDetail : function() {
		this.detailForm.getForm().reset();
		if (this.selModel.getSelections().length < 1) {
			Ext.Msg.alert('提示', '请选择一项!');
			return;
		}
		
		window.open('capply_preReview.do?copyrightApplication.id=' + this.selModel.getSelections()[0].id);

		/*this.detailWindow.show();

		var selRec = this.selModel.getSelections()[0];
		this.detailForm.getForm().loadRecord(selRec);*/
	},
	doRefuse : function() {
		if (this.selModel.getSelections().length < 1) {
			Ext.Msg.alert('提示', '请选择一项!');
			return;
		}

		this.el.mask("审核中...", 'x-mask-loading');

		Ext.Ajax.request({
			url : this.review_url,
			params : {
				// mapping to field named 'msisdn' of
				// mobileUserSearchAction at the backend
				'copyrightApplication.id' : this.selModel.getSelections()[0].id,
				'copyrightApplication.state' : 4
			},
			success : function(resp) {
				var rp = Ext.decode(resp.responseText);
				this.el.unmask();
				this.detailWindow.hide();
				if (rp.success == true) {
					Ext.MessageBox.alert('提示', '审核不通过!');
					this.store.load(this.params);
				} else if (rp.success == false) {
					Ext.MessageBox.alert('错误', '错误信息:' + rp.message);
				}
			},
			scope : this

		});
	},
	doReview : function() {

		if (this.selModel.getSelections().length < 1) {
			Ext.Msg.alert('提示', '请选择一项!');
			return;
		}

		this.el.mask("审核中...", 'x-mask-loading');

		Ext.Ajax.request({
			url : this.review_url,
			params : {
				// mapping to field named 'msisdn' of
				// mobileUserSearchAction at the backend
				'copyrightApplication.id' : this.selModel.getSelections()[0].id,
				'copyrightApplication.state' : 2

			},
			success : function(resp) {
				var rp = Ext.decode(resp.responseText);
				this.el.unmask();
				this.detailWindow.hide();
				if (rp.success == true) {
					this.store.load(this.params);
				} else if (rp.success == false) {
					Ext.MessageBox.alert('错误', '错误信息:' + rp.message);
				}
			},
			scope : this

		});
	}
		/* end of handler implementation */
});

Ext.reg("apply_review_grid", crs.grid.ApplyingFormReviewGridPanel);